package com.tozed.widget;

import com.tozed.test.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class AutomaticTestView extends LinearLayout {
	
	public Button mBtnAutoTest;
	public EditText mEtAutoTestCount;
	public EditText mEtSuccessCount;
	public EditText mEtFailedCount;
	
	public AutomaticTestView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		LayoutInflater inflater = LayoutInflater.from(context);
		inflater.inflate(R.layout.automatic_test, this);
		
		mBtnAutoTest =(Button)findViewById(R.id.btnAutoTest);
		mEtAutoTestCount = (EditText)findViewById(R.id.etCount);
		mEtAutoTestCount.setText("10");
		mEtSuccessCount = (EditText)findViewById(R.id.etSuccessCount);
		mEtSuccessCount.setText("0");
		mEtFailedCount = (EditText)findViewById(R.id.etFailedCount);
		mEtFailedCount.setText("0");
	}

	public void setOnClickListener(OnClickListener l) {
		if (l != null) {
			mBtnAutoTest.setOnClickListener(l);
		}
	}
	
	public int getAutomaticTestCount() {
		String strCount = mEtAutoTestCount.getText().toString();
		
		if (strCount == null || strCount.isEmpty()) {
			return 0;
		}
		
		return Integer.parseInt(strCount);
	}
	
	public void setAutomaticTestResult(int successCnt, int failedCnt) {
		mEtSuccessCount.setText(String.valueOf(successCnt));
		mEtFailedCount.setText(String.valueOf(failedCnt));
	}
}
